﻿<Page
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing"
	  xmlns:v="clr-namespace:MovieRental_Presentation.Validation"
	  x:Class="MovieRental_Presentation.MovieDetails"
      d:DesignWidth="1024" d:DesignHeight="600"
      mc:Ignorable="d"
      WindowTitle="Movie Rental"
	  MinWidth="900"
	  MinHeight="500" 
      ShowsNavigationUI="False">

    <Grid Background="{StaticResource backgroundBrush}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="250"/>
        </Grid.ColumnDefinitions>
        <Border BorderThickness="{StaticResource borderThickness}" Padding="{StaticResource borderPadding}" Margin="8" CornerRadius="{StaticResource borderCornerRadius}" BorderBrush="{StaticResource borderBrush}" Grid.Column="1">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <StackPanel Grid.Row="0">
                    <Label Content="Menu" HorizontalAlignment="Center" Style="{StaticResource MenuLabelStyle}"/>
                    <Button x:Name="dashboardButton" Content="Dashboard" Height="40" Margin="0,8" Template="{StaticResource MenuButtonTemplate}" Click="dashboardButton_Click"/>
                    <Button x:Name="customersButton" Content="Customers" Height="40" Margin="0,8" Template="{StaticResource MenuButtonTemplate}" Click="customersButton_Click"/>
                    <Button x:Name="moviesButton" Content="Movies" Height="40" Margin="0,8" Template="{StaticResource MenuButtonTemplate}" Click="moviesButton_Click"/>
                    <Button x:Name="statisticsButton" Content="Statistics" Height="40" Margin="0,8" Template="{StaticResource MenuButtonTemplate}" Click="statisticsButton_Click"/>
                </StackPanel>
                <Frame Content="Frame" Grid.Row="1" Source="/MovieRental.Presentation;component/Cart.xaml" NavigationUIVisibility="Hidden" Margin="0"/>
            </Grid>
        </Border>
        <Border Grid.Column="0" BorderBrush="{StaticResource borderBrush}" BorderThickness="{StaticResource borderThickness}" Margin="8" Padding="{StaticResource borderPadding}" CornerRadius="{StaticResource borderCornerRadius}">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Label Content="Movie Details" Margin="0" d:LayoutOverrides="Height" HorizontalAlignment="Center" VerticalAlignment="Center" Style="{StaticResource MenuLabelStyle}"/>
                <Button x:Name="backButton" Content="Back" HorizontalAlignment="Left" Margin="8,8,0,8.413" Width="66.493" d:LayoutOverrides="Height" Click="backButton_Click" />
                <Grid Grid.Row="1">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Expander Margin="8" ExpandDirection="Right">
                        <Expander.Header>
                            <TextBlock RenderTransformOrigin="0.5,0.5" Margin="0,30,0,0" FontSize="{StaticResource menuButtonTextSize}" Foreground="{StaticResource borderBrush}"><TextBlock.RenderTransform>
									<RotateTransform Angle="-90"/>
								</TextBlock.RenderTransform><Run Text="Editions"/></TextBlock>
                        </Expander.Header>
                        <Grid MinWidth="150" Margin="0,0,8,0" MaxWidth="400">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <DataGrid Grid.Row="0" ItemsSource="{Binding EditionsList}"  Name="editionsDataGrid" SelectedItem="{Binding SelectedEdition, Mode=TwoWay}" AutoGenerateColumns="False">
                                <DataGrid.Columns>
                                    <DataGridTextColumn Header="Publisher" Width="*" Binding="{Binding Entity.Publisher}"/>
                                    <DataGridTextColumn Header="Media Type" Width="*" Binding="{Binding MediaTypeName}"/>
                                    <DataGridTextColumn Header="Price Per Day" Width="*" Binding="{Binding Path=Entity.PricePerDay, StringFormat=\{0:c\}}"/>
                                    <DataGridTextColumn Header="In Stock" Width="Auto" Binding="{Binding InStockQuantity}"/>
                                    <DataGridTextColumn Header="Discount" Width="Auto" Binding="{Binding Path=DiscountValue, StringFormat=\{0\}\%}"/>
                                </DataGrid.Columns>
                            </DataGrid>
                            <StackPanel Grid.Row="1" Margin="0,8" Orientation="Horizontal" HorizontalAlignment="Center" Name="manageEditionPanel">
                                <Button Content="Add" Width="40" Height="40" Margin="0" Name="addButton" Click="addButton_Click" />
                                <Button Content="Edit" Height="40" Width="40" Margin="8,0,0,0" Visibility="{Binding ElementName=editionsDataGrid, Path=SelectedIndex, Converter={StaticResource indexVisibilityConverter}}" Name="editEditionButton" Click="editEditionButton_Click" />
                                <Button Content="Add to Cart" Width="40" Height="40" Margin="8,0,0,0" Name="addToCartButton" Visibility="{Binding ElementName=editionsDataGrid, Path=SelectedIndex, Converter={StaticResource indexVisibilityConverter}}" Click="addToCartButton_Click" />
                                <Button Content="Delete" Width="40" Height="40" Margin="8,0,0,0" Name="deleteButton" Visibility="{Binding ElementName=editionsDataGrid, Path=SelectedIndex, Converter={StaticResource indexVisibilityConverter}}" Click="deleteButton_Click" />
                                <Button Content="ManageDiscounts" Width="40" Height="40" Margin="8,0,0,0" Name="manageDiscountButton" Visibility="{Binding ElementName=editionsDataGrid, Path=SelectedIndex, Converter={StaticResource indexVisibilityConverter}}" Click="manageDiscountButton_Click" />
                            </StackPanel>
                            <Grid Grid.Row="2" Name="editionGrid" DataContext="{Binding SelectedEdition.Entity}" Visibility="Collapsed">
                                <Grid.RowDefinitions>
                                    <RowDefinition/>
                                    <RowDefinition/>
                                    <RowDefinition/>
                                    <RowDefinition/>
                                    <RowDefinition/>
                                    <RowDefinition/>
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <TextBlock Grid.Row="0" Grid.ColumnSpan="2" Text="Manage edition" HorizontalAlignment="Center" FontSize="{StaticResource infoTextSize}" Foreground="{StaticResource borderBrush}" Margin="8"/>
                                <TextBlock Grid.Row="1" Grid.Column="0" Text="Publisher" Foreground="{StaticResource inputBoxBrush}" FontSize="{StaticResource infoTextSize}" Margin="0,8"/>
                                <TextBlock Grid.Row="2" Grid.Column="0" Text="Media Type" Foreground="{StaticResource inputBoxBrush}" FontSize="{StaticResource infoTextSize}" Margin="0,8"/>
                                <TextBlock Grid.Row="3" Grid.Column="0" Text="Price Per Day" Foreground="{StaticResource inputBoxBrush}" FontSize="{StaticResource infoTextSize}" Margin="0,8"/>
                                <TextBlock Grid.Row="4" Grid.Column="0" Text="Quantity" Foreground="{StaticResource inputBoxBrush}" FontSize="{StaticResource infoTextSize}" Margin="0,8"/>
                                <TextBox x:Name="publisherTextBox" Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" Style="{StaticResource InputTextBoxStyle}">
                                	<TextBox.Text>
                                		<Binding Path="Publisher" Mode="TwoWay">
                                			<Binding.ValidationRules>
                                				<v:RequiredValidationRule ValidatesOnTargetUpdated="True"/>                     			
											</Binding.ValidationRules>                      		
										</Binding>                       	
									</TextBox.Text>
                                </TextBox>
                                <ComboBox ItemsSource="{Binding MediaTypes}"  SelectedItem="{Binding MediaTypeName}" Grid.Row="2" Grid.Column="1" VerticalAlignment="Center" FontSize="{StaticResource infoTextSize}" Name="mediaTypesComboBox" SelectionChanged="mediaTypesComboBox_SelectionChanged" />
                                <TextBox  x:Name="priceTextBox" Grid.Row="3" Grid.Column="1" VerticalAlignment="Center" Style="{StaticResource InputTextBoxStyle}">
                                	<TextBox.Text>
                                		<Binding Path="PricePerDay" Mode="TwoWay">
                                			<Binding.ValidationRules>
                                				<v:PricePerDayValidationRule ValidatesOnTargetUpdated="True" ValidationStep="ConvertedProposedValue"/>                     			
											</Binding.ValidationRules>                      		
										</Binding>                       	
									</TextBox.Text>
                                </TextBox>
                                <TextBox x:Name="quantityTextBox" Grid.Row="4" Grid.Column="1" VerticalAlignment="Center" Style="{StaticResource InputTextBoxStyle}"/>
                                <Button Grid.Row="5" Grid.Column="0" Content="Add" Margin="0,8,4,8" Name="applyEditionChangesButton" Click="applyEditionChangesButton_Click" />
                                <Button Grid.Row="5" Grid.Column="1" Content="Cancel" Margin="4,8,0,8" Name="cancelEditionChangesButton" Click="cancelEditionChangesButton_Click" />
                            </Grid>
                            <Grid Grid.Row="3" Name="manageDiscountGrid" Visibility="Collapsed">
                                <Grid.RowDefinitions>
                                    <RowDefinition/>
                                    <RowDefinition/>
                                    <RowDefinition/>
                                    <RowDefinition/>
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <TextBlock Grid.Row="0" Grid.ColumnSpan="2" Text="Manage Discount" HorizontalAlignment="Center" FontSize="{StaticResource infoTextSize}" Foreground="{StaticResource borderBrush}" Margin="8"/>
                                <TextBlock Grid.Row="1" Grid.Column="0" Text="Valid Until" Foreground="{StaticResource inputBoxBrush}" FontSize="{StaticResource infoTextSize}" Margin="0,8"/>
                                <TextBlock Grid.Row="2" Grid.Column="0" Text="Value" Foreground="{StaticResource inputBoxBrush}" FontSize="{StaticResource infoTextSize}" Margin="0,8"/>
                                <DatePicker x:Name="validUntilDatePicker" Grid.Column="1" Margin="0" Grid.Row="1" VerticalAlignment="Center" Style="{StaticResource DatePickerStyle}" >
                                	<DatePicker.SelectedDate>
                                		<Binding Path="DiscountValidUntil" Mode="TwoWay">
                                			<Binding.ValidationRules>
                                				<v:DiscountValidUntilValidationRule ValidatesOnTargetUpdated="True"/>                     			
											</Binding.ValidationRules>                      		
										</Binding>                       	
									</DatePicker.SelectedDate>
                                </DatePicker>
                                <TextBox x:Name="discountValueTextBox" Grid.Row="2" Grid.Column="1" VerticalAlignment="Center" Style="{StaticResource InputTextBoxStyle}">
                                	<TextBox.Text>
                                		<Binding Path="DiscountValue" Mode="TwoWay">
                                			<Binding.ValidationRules>
                                				<v:DiscountValueValidationRule ValidatesOnTargetUpdated="True" ValidationStep="ConvertedProposedValue"/>                     			
											</Binding.ValidationRules>                      		
										</Binding>                       	
									</TextBox.Text>
                                </TextBox>
                                <Button Grid.Row="3" Grid.Column="0" Content="Apply" Margin="0,8,4,8" Name="applyDiscountButton" Click="applyDiscountButton_Click" />
                                <Button Grid.Row="3" Grid.Column="1" Content="Cancel" Margin="4,8,0,8" Name="cancelDiscountButton" Click="cancelDiscountButton_Click" />
                                <Button Content="R" HorizontalAlignment="Right" Margin="0" Width="20" Grid.Column="1" Height="20" VerticalAlignment="Center" Name="defaultDiscountButton" Click="defaultDiscountButton_Click" />
                            </Grid>


                        </Grid>
                    </Expander>
                    <Grid Grid.Column="1" Margin="0,0,0,8">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <Grid Margin="0,0,0,8">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="3*"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="1*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <TextBlock Margin="0" Text="Title" Foreground="{StaticResource inputBoxBrush}" FontSize="{StaticResource infoTextSize}" VerticalAlignment="Center"/>
                            <TextBox x:Name="titleTextBox" Margin="8,0" VerticalAlignment="Center" Grid.Column="1" Grid.Row="0" IsReadOnly="{Binding IsReadOnly}" Style="{DynamicResource InputTextBoxStyle}">
                            	<TextBox.Text>
                            		<Binding Path="Movie.Entity.Title" Mode="TwoWay">
                            			<Binding.ValidationRules>
                            				<v:RequiredValidationRule ValidatesOnTargetUpdated="True"/>
										</Binding.ValidationRules>                   		
									</Binding>                    	
								</TextBox.Text>
                            </TextBox>
                            <TextBox x:Name="imdbRatingTextBox" Margin="8,0" VerticalAlignment="Center" Grid.Column="1" Grid.Row="1" IsReadOnly="{Binding IsReadOnly}" Style="{DynamicResource InputTextBoxStyle}">
                            	<TextBox.Text>
                            		<Binding Path="Movie.Entity.ImdbRating" Mode="TwoWay">
                            			<Binding.ValidationRules>
                            				<v:ImdbRatingValidationRule ValidatesOnTargetUpdated="True" ValidationStep="ConvertedProposedValue"/>                  			
										</Binding.ValidationRules>                   		
									</Binding>                    	
								</TextBox.Text>
                            </TextBox>
                            <TextBox x:Name="webPageTextBox" Margin="8,0" Grid.Column="1" Grid.Row="2" VerticalAlignment="Center" IsReadOnly="{Binding IsReadOnly}" Style="{DynamicResource InputTextBoxStyle}">
                            	<TextBox.Text>
                            		<Binding Path="Movie.Entity.WebPage" Mode="TwoWay">
                            			<Binding.ValidationRules>
                            				<v:WebPageValidationRule ValidatesOnTargetUpdated="True"/>                  			
										</Binding.ValidationRules>                   		
									</Binding>                    	
								</TextBox.Text>
                            </TextBox>
                            <TextBlock Text="IMDB Rating" Foreground="{StaticResource inputBoxBrush}" FontSize="{StaticResource infoTextSize}" Grid.Row="1"  VerticalAlignment="Center"/>
                            <TextBlock Text="Web Page" Foreground="{StaticResource inputBoxBrush}" FontSize="{StaticResource infoTextSize}" Grid.Row="2"  VerticalAlignment="Center"/>
                            <TextBlock Text="Editions:" Foreground="{StaticResource inputBoxBrush}" FontSize="{StaticResource infoTextSize}" HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Column="2" Margin="-0.001,0,0,0"/>
                            <TextBlock Foreground="{StaticResource inputBoxBrush}" FontSize="{StaticResource infoTextSize}" Grid.Column="2" Margin="0,0,-0.001,0" Grid.Row="1" VerticalAlignment="Center" Text="Loans:"/>
                            <TextBlock Margin="0,0,8,0" Text="{Binding Movie.EditionsCount}" Grid.Row="0" Grid.Column="3" Foreground="{StaticResource inputBoxBrush}" FontSize="{StaticResource infoTextSize}" VerticalAlignment="Center" HorizontalAlignment="Right"/>
                            <TextBlock Margin="0,0,8,0" Text="{Binding Movie.NotReturnedLoansCount}" Grid.Row="1" Grid.Column="3" Foreground="{StaticResource inputBoxBrush}" FontSize="{StaticResource infoTextSize}" VerticalAlignment="Center" HorizontalAlignment="Right"/>
                            <StackPanel Grid.Column="4" Grid.Row="0" Grid.RowSpan="2" Orientation="Horizontal">
                                <Button Content="Delete" Width="40" Height="40" Margin="8" Name="deleteMovieButton" Click="deleteMovieButton_Click" />
                                <Button Content="Edit" Width="40" Height="40" Margin="8" Visibility="{Binding Path=IsReadOnly, Converter={StaticResource booleanToVisibilityConverter}}" Name="editMovieButton" Click="editMovieButton_Click" />
                            </StackPanel>
                            <StackPanel Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal" Visibility="{Binding Path=IsReadOnly, Converter={StaticResource boolToVisibilityReverseConverter}}">
                                <Button Content="Apply" Margin="0,8,8,8" Width="100" Name="applyMovieChangesButton" Click="applyMovieChangesButton_Click" />
                                <Button Content="Cancel" Margin="0,8,8,8" Width="100" Name="cancelMovieChangesButton" Click="cancelMovieChangesButton_Click" />
                            </StackPanel>
                            

                        </Grid>
                        <Frame Grid.Row="1" Content="" Name="webPageFrame" Source="{Binding Movie.Entity.WebPage}" JournalOwnership="OwnsJournal" NavigationUIVisibility="Hidden" />
                        <Grid x:Name="loadingGrid" HorizontalAlignment="Center" Margin="0" Grid.Row="1" Height="Auto" VerticalAlignment="Center">
                        	<Grid.ColumnDefinitions>
                        		<ColumnDefinition Width="Auto"/>
                        		<ColumnDefinition Width="200"/>
                        	</Grid.ColumnDefinitions>
                        	<TextBlock Margin="0,0,16,0" TextWrapping="Wrap" Text="Loading" VerticalAlignment="Center" Foreground="{StaticResource inputBoxBrush}" FontSize="{StaticResource labelTitleSize}"/>
                        	<ProgressBar Grid.Column="1" Margin="0" VerticalAlignment="Center" Height="25" IsIndeterminate="True"/>
                        </Grid>
                    </Grid>
                </Grid>

            </Grid>
        </Border>

    </Grid>
</Page>